package br.com.visagio.aulabigdata.job;

import java.util.ArrayList;
import java.util.List;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import twitter4j.TwitterException;

import br.com.visagio.aulabigdata.business.TwitterBusiness;
import br.com.visagio.aulabigdata.enums.DB;

public class TwitterJob implements Job {
	
	Logger logger = LoggerFactory.getLogger(TwitterJob.class);

	TwitterBusiness twitterBusiness = new TwitterBusiness();

	public void execute(JobExecutionContext context) {
		
		List<DB> databases = new ArrayList<DB>();
		databases.add(DB.MYSQL);
		databases.add(DB.SOLR);
		
		twitterBusiness.setDatabaseOption(databases);
		
		try {
			twitterBusiness.searchAndSaveLatestTweets();
		} catch (TwitterException e) {
			logger.error("Erro ao tentar buscar tweets pela hashtag " + e.getMessage());
		} catch (Exception e) {
			logger.error("Falha ao executar job.", e);
		}
	}
	
}
